package com.kod.actor;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import com.badlogic.gdx.utils.Disposable;

public class Card extends Image implements Disposable {
	private static TextureAtlas cc;
	private static AtlasRegion ar;
	private static TextureRegion[][] trs;
	Image image;
	public int data, color;

	public Card(int value) {
		super();
		if (cc == null) {
			cc = new TextureAtlas(Gdx.files.internal("ccc.atlas"));
			ar = cc.findRegion("CARD");
			trs = ar.split(76, 103);
		}
		int _color = value % 1000;
		int _value = (value - _color) / 1000;
		data = _value;
		color = _color;
		_color = _color % 100;
		_value = _value - 1;
		_value = _value == 13 ? 0 : _value;
		_value = _value == 19 ? 1 : _value;
		image = new Image(trs[_color][_value]);
		setDrawable(image.getDrawable());
		// setWidth(image.getPrefWidth());
		// setHeight(image.getPrefHeight());

	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		// image.draw(batch, parentAlpha);
		super.draw(batch, parentAlpha);
		// image.setX(this.getX());
		// image.setY(this.getY());
		// image.setScaleX(this.getScaleX());
		// image.setScaleY(this.getScaleY());
		// image.draw(batch, parentAlpha);
	}

	@Override
	public void dispose() {
		image.remove();
	}
}
